﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Amrta.Export.Excel;
using CommunitySystem.Assert;
using CommunitySystem.Ctrls;
using CommunitySystem.EmpbasicService;
using CommunitySystem.PageView;
using CommunitySystem.PageView.EmpBasicManager;
using CommunitySystem.Views;
using EHR.Common;
using org.in2bits.MyXls;
using System.Windows.Media.Imaging;
using CommunitySystem.Common;
using CommunitySystem.CustomerQuery;
using System.Text;
using System.Reflection;

namespace CommunitySystem
{
    public class ShiTi
    {
        public string ygzt { get; set; }
    }

    public partial class EmpbasicControl : AsyncCtrl, IReturnListenerc
    {
        public String[] Oldorgids;
        public int KaiGuan = 0;//0为导出人员信息表，1为导出个人信息表
        private EmpbasicService.BianZhiModel model = new EmpbasicService.BianZhiModel();
        public NavMoveSwitch Nav { get; set; }
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        private CustomerQuery.CustomerQueryClient CustomerQueryClient = new CustomerQuery.CustomerQueryClient();
        private ShiTi shiti = new ShiTi();
        #region IReturnListenerc 成员

        public void BeginReturn()
        {
            //string ss = "";
            //foreach (string ii in orgids)
            //    ss += ii + ",";
            //if (ss.Length > 1)
            //    ss = ss.Substring(0, ss.Length - 1);
            //else ss = "0";
            //string condition  = GetHightCondition();
            //if (condition != null)
            //{
            //    Client.GetEmp_BasicInfoAsync(ss, "0", ChaName.Text, type, 0, 20, "在职", condition);
            //    Client.GetEmp_BasicInfoCountsAsync(ss, "0", ChaName.Text, type, "在职", condition);
            //}
        }

        #endregion
        public EmpbasicControl()
        {
            InitializeComponent();
            
            CustomerQueryClient.GetQuery_ColumnCollectionCompleted += new EventHandler<CustomerQuery.GetQuery_ColumnCollectionCompletedEventArgs>(CustomerQueryClient_GetQuery_ColumnCollectionCompleted);
            CustomerQueryClient.GetQuery_ColumnCollectionAsync("1=1");
            CustomerQueryClient.GetValuesCompleted += new EventHandler<GetValuesCompletedEventArgs>(CustomerQueryClient_GetValuesCompleted);
            _gridClickManagerXQ = new MouseClickManager(DGRole, 300);
            _gridClickManagerXQ.DoubleClick += new System.Windows.Input.MouseButtonEventHandler(_gridClickManagerXQ_DoubleClick);
            selectedempmodel.Clear();
            ListBoxOfLife.Items.Clear();
            DGRole.ColumnDisplayIndexChanged += new EventHandler<DataGridColumnEventArgs>(DGRole_ColumnDisplayIndexChanged);
            Client.GetDengLuJueSeCompleted += new EventHandler<EmpbasicService.GetDengLuJueSeCompletedEventArgs>(Client_GetDengLuJueSeCompleted);
            Client.GetDengLuJueSeAsync(Session.LoginUser.LoginName);
            this.KeyDown += new KeyEventHandler(EmpbasicControl_KeyDown);
            Client.GetEmp_BasicInfoCountsCompleted += new EventHandler<EmpbasicService.GetEmp_BasicInfoCountsCompletedEventArgs>(Client_GetEmp_BasicInfoCountsCompleted);
            Client.GetBianZhiModelShiYouCompleted += new EventHandler<EmpbasicService.GetBianZhiModelShiYouCompletedEventArgs>(Client_GetBianZhiModelShiYouCompleted);
            Client.GetEmp_BasicInfoCompleted += new EventHandler<EmpbasicService.GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
            Client.GetLieByUserIDCompleted += new EventHandler<GetLieByUserIDCompletedEventArgs>(Client_GetLieByUserIDCompleted);
            Client.UpdateLieCompleted += new EventHandler<UpdateLieCompletedEventArgs>(Client_UpdateLieCompleted);
            Client.GetOrgForHRModelbyIDsCompleted += new EventHandler<EmpbasicService.GetOrgForHRModelbyIDsCompletedEventArgs>(Client_GetOrgForHRModelbyIDsCompleted);
            Client.GetOrgForHRModelCompleted += new EventHandler<EmpbasicService.GetOrgForHRModelCompletedEventArgs>(Client_GetOrgForHRModelCompleted);
            Client.GetDengLuOrgCompleted += new EventHandler<EmpbasicService.GetDengLuOrgCompletedEventArgs>(Client_GetDengLuOrgCompleted);
            shiti.ygzt = "在职";
            ygzt.DataContext = shiti;
            //ygzt.OnSelectionChanged += new OnSelectionChangedEvent(ygzt_OnSelectionChanged);
            //LoadData("0");
        }

        //private string StatusForChaXun = "";
        //void ygzt_OnSelectionChanged(object sender, object NewValue, object OldValue)
        //{
        //    StatusForChaXun = NewValue.ToString();
        //}

        void EmpbasicControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ChaData_Click(null, null);
            }
        }

       

        /// <summary>
        /// 获得所有查询字段
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CustomerQueryClient_GetQuery_ColumnCollectionCompleted(object sender, CustomerQuery.GetQuery_ColumnCollectionCompletedEventArgs e)
        {
            _AllColumnCollection = e.Result;
        }

        private System.Collections.ObjectModel.ObservableCollection<CommunitySystem.CustomerQuery.Query_ColumnCollection> _AllColumnCollection = null;

        

        #region 右键

        private readonly MouseClickManager _gridClickManagerXQ;
        private void dgXQ_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.MouseLeftButtonUp += _gridClickManagerXQ.HandleClick;
            //右击小区
            RightMenuXQ(e);
        }
        private void RightMenuXQ(DataGridRowEventArgs e)
        {
            DataGridRow dgr = e.Row;
            Emp_BasicInfoModel XQ = (Emp_BasicInfoModel)dgr.DataContext;

            System.Windows.Controls.ContextMenu cm = new System.Windows.Controls.ContextMenu();
            System.Windows.Controls.MenuItem miUP = new System.Windows.Controls.MenuItem();
            miUP.Header = "编辑";
            miUP.Click += new RoutedEventHandler(miUP_Click);

            System.Windows.Controls.MenuItem miDE = new System.Windows.Controls.MenuItem();
            miDE.Header = "删除";
            miDE.Click += new RoutedEventHandler(miDE_Click);

            System.Windows.Controls.MenuItem miAdd = new System.Windows.Controls.MenuItem();
            miAdd.Header = "查看详细信息";
            miAdd.Click += new RoutedEventHandler(miAdd_Click);


            cm.Items.Add(miUP);
            cm.Items.Add(miDE);
            cm.Items.Add(miAdd);

            ContextMenuService.SetContextMenu(dgr, cm);
        }
        void miUP_Click(object sender, RoutedEventArgs e)
        {
            Emp_BasicInfoModel selxq = ((System.Windows.Controls.MenuItem)sender).DataContext as Emp_BasicInfoModel;

            if (selxq != null)
            {
                EmpbasicWindow RMWindow = new EmpbasicWindow(selxq.ID, false, orgid,shiti.ygzt);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的人员！"); 
        }
        void miDE_Click(object sender, RoutedEventArgs e)
        {
            Emp_BasicInfoModel selxq = ((System.Windows.Controls.MenuItem)sender).DataContext as Emp_BasicInfoModel;

            if (selxq != null)
            {
                if (MessageBox.Show("确定删除吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    Client.DeleteEmp_BasicInfoCompleted -= new EventHandler<EmpbasicService.DeleteEmp_BasicInfoCompletedEventArgs>(Client_DeleteEmp_BasicInfoCompleted);
                    Client.DeleteEmp_BasicInfoCompleted += new EventHandler<EmpbasicService.DeleteEmp_BasicInfoCompletedEventArgs>(Client_DeleteEmp_BasicInfoCompleted);
                    Client.DeleteEmp_BasicInfoAsync("(" + selxq.ID.ToString() + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要删除的人员！"); 
        }
        void miAdd_Click(object sender, RoutedEventArgs e)
        {
            Emp_BasicInfoModel selxq = ((System.Windows.Controls.MenuItem)sender).DataContext as Emp_BasicInfoModel;

            if (selxq != null)
            {
                OtherEmpInfo view = new OtherEmpInfo(selxq.ID);
                Nav.ShowNextPage(selxq.Name + "-详细信息", view, this);

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要查看的人员！"); 
        }
        private void _gridClickManagerXQ_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            var selxq = this.DGRole.SelectedItem as Emp_BasicInfoModel;
            if (selxq != null)
            {
                EmpbasicWindow RMWindow = new EmpbasicWindow(selxq.ID, false, orgid, shiti.ygzt);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的人员！"); 
        }
        #endregion

        #region checkbox全选
        private CheckBox GetCheckBoxWithParent(UIElement parent, Type targetType, string CheckBoxName)
        {
            if (parent.GetType() == targetType && ((CheckBox)parent).Name == CheckBoxName)
            {
                return (CheckBox)parent;
            }
            CheckBox result = null;
            int count = VisualTreeHelper.GetChildrenCount(parent);
            for (int i = 0; i < count; i++)
            {
                UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);

                if (GetCheckBoxWithParent(child, targetType, CheckBoxName) != null)
                {
                    result = GetCheckBoxWithParent(child, targetType, CheckBoxName);
                    break;
                }
            }
            return result;
        }
        public ObservableCollection<EmpbasicService.Emp_BasicInfoModel> selectedempmodel =
            new ObservableCollection<EmpbasicService.Emp_BasicInfoModel>();
        private void cbAll_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox chk = sender as CheckBox;
            bool check = chk.IsChecked.Value;
            if (check)
            {
                foreach (EmpbasicService.Emp_BasicInfoModel item in empmodel)
                {

                    this.selectedempmodel.Add(item);
                    chk = this.DGRole.Columns[0].GetCellContent(item) as CheckBox;
                    if (chk != null)
                        chk.IsChecked = true;
                }
            }
            else
            {
                foreach (EmpbasicService.Emp_BasicInfoModel item in empmodel)
                {
                    chk = DGRole.Columns[0].GetCellContent(item) as CheckBox;
                    if (chk != null)
                        chk.IsChecked = false;
                }

                this.selectedempmodel.Clear();
            }
        }
        void DGRole_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            CheckBox chk = this.DGRole.Columns[0].GetCellContent(e.Row) as CheckBox;
            chk.IsChecked = false;
            chk.Click += new RoutedEventHandler(cb_Click);
        }
        private void cb_Click(object sender, RoutedEventArgs e)
        {
            CheckBox chk = sender as CheckBox;
            bool check = chk.IsChecked.Value;
            EmpbasicService.Emp_BasicInfoModel p = chk.DataContext as EmpbasicService.Emp_BasicInfoModel;
            if (check)
            {
                if (!this.selectedempmodel.Contains(p))
                    selectedempmodel.Add(p);
            }
            else
            {
                selectedempmodel.Remove(p);
            }
        }


        #endregion

        /// <summary>
        /// 判断用户输入是否为日期
        /// </summary>
        /// <param name="strValue"></param>
        /// <returns></returns>
        /// <remarks>
        /// 可判断格式如下（其中-可替换为/，不影响验证)
        /// YYYY | YYYY-MM | YYYY-MM-DD | YYYY-MM-DD HH:MM:SS | YYYY-MM-DD HH:MM:SS.FFF
        /// </remarks>
        public static bool IsDateTime(string strValue)
        {
            if (null == strValue)
            {
                return false;
            }

            string regexDate = @"[1-2]{1}[0-9]{3}((-|\/){1}(([0]?[1-9]{1})|(1[0-2]{1}))((-|\/){1}((([0]?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1})))( (([0-1]{1}[0-9]{1})|2[0-3]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{3})?)?)?)?$";

            if (Regex.IsMatch(strValue, regexDate))
            {
                //以下各月份日期验证，保证验证的完整性
                int _IndexY = -1;
                int _IndexM = -1;
                int _IndexD = -1;

                if (-1 != (_IndexY = strValue.IndexOf("-")))
                {
                    _IndexM = strValue.IndexOf("-", _IndexY + 1);
                    _IndexD = strValue.IndexOf(":");
                }
                else
                {
                    _IndexY = strValue.IndexOf("/");
                    _IndexM = strValue.IndexOf("/", _IndexY + 1);
                    _IndexD = strValue.IndexOf(":");
                }

                //不包含日期部分，直接返回true
                if (-1 == _IndexM)
                    return true;

                if (-1 == _IndexD)
                {
                    _IndexD = strValue.Length + 3;
                }

                int iYear = Convert.ToInt32(strValue.Substring(0, _IndexY));
                int iMonth = Convert.ToInt32(strValue.Substring(_IndexY + 1, _IndexM - _IndexY - 1));
                int iDate = Convert.ToInt32(strValue.Substring(_IndexM + 1, _IndexD - _IndexM - 4));

                //判断月份日期
                if ((iMonth < 8 && 1 == iMonth % 2) || (iMonth > 8 && 0 == iMonth % 2))
                {
                    if (iDate < 32)
                        return true;
                }
                else
                {
                    if (iMonth != 2)
                    {
                        if (iDate < 31)
                            return true;
                    }
                    else
                    {
                        //闰年
                        if ((0 == iYear % 400) || (0 == iYear % 4 && 0 < iYear % 100))
                        {
                            if (iDate < 30)
                                return true;
                        }
                        else
                        {
                            if (iDate < 29)
                                return true;
                        }
                    }
                }
            }

            return false;
        }

        void LoadData(string orgid)
        {
             string condition  = GetHightCondition();
             if (condition != null)
             {
                 searchCondition = new string[6] { orgid, "0", ChaName.Text, type, shiti.ygzt, condition };
                 Client.GetEmp_BasicInfoCountsAsync(orgid, "0", ChaName.Text, type, shiti.ygzt, condition);
                 rootIndicator.BusyContent = "查询数据....";
                 rootIndicator.IsBusy = true;
                 //Client.GetEmp_BasicInfoAsync(orgid, "0", ChaName.Text, type, 0, 20, "在职", condition);

             }
            //Client.GetEmp_BasicInfoCountsCompleted += (sender, e) =>
            //                                      {
            //                                          int count = e.Result;
            //                                          List<int> source = new List<int>();
            //                                          for (int i = 0; i < count; i++)
            //                                          {
            //                                              source.Add(i + 1);
            //                                              dataPager1.PageSize = 1;
            //                                              dataPager1.Source = source;
            //                                          }
            //                                      };

            
            if(!string.IsNullOrEmpty(orgid))
            {
                
                Client.GetBianZhiModelShiYouAsync(Convert.ToInt32(orgid.Split(',')[0]));
            }
           
        }
        public ObservableCollection<EmpbasicService.Emp_BasicInfoModel> empmodel =
            new ObservableCollection<EmpbasicService.Emp_BasicInfoModel>();

        private int LastID = 0;
        void Client_GetEmp_BasicInfoCompleted(object sender, EmpbasicService.GetEmp_BasicInfoCompletedEventArgs e)
        {
            //List<EmpbasicService.Emp_BasicInfoModel> tt = null;
            //if (DGRole.SelectedItems.Count > 0)
            //{
            //    tt = DGRole.GetSelectedItems<EmpbasicService.Emp_BasicInfoModel>();
            //    if (tt.Count > 0)
            //    {
            //        foreach (EmpbasicService.Emp_BasicInfoModel i in tt)
            //        {
            //            if (e.Result.Where(p => p.ID == i.ID).FirstOrDefault() == null)
            //                e.Result.Add(i);
            //            else e.Result.Remove(i);

            //        }
            //    }
            //}
            empmodel.Clear();
            //selectedempmodel.Clear();
            foreach (EmpbasicService.Emp_BasicInfoModel i in e.Result)
            {
                if (empmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                {
                    empmodel.Add(i);
                }
            }
            foreach (EmpbasicService.Emp_BasicInfoModel i in selectedempmodel)
            {
                if (e.Result.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == true)
                {
                    e.Result.Where(p => p.ID == i.ID).FirstOrDefault().IsSelected = true;
                }
            }
            foreach (var i in e.Result)
            {
                i.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(i_PropertyChanged);
            }
            DGRole.ItemsSource = e.Result;
            
            Client.GetLieByUserIDAsync(Session.LoginUser.UserID);
            
            rootIndicator.IsBusy = false;
        }

        void i_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("IsSelected"))
            {
                var mode = sender as Emp_BasicInfoModel;
                if (mode.IsSelected == true)
                {
                    if (selectedempmodel.Where(c => c.ID == mode.ID).Count() <= 0)
                    {
                        selectedempmodel.Add(mode);
                    }
                }
                else
                {
                    var i = selectedempmodel.Where(c => c.ID == mode.ID).FirstOrDefault();
                    if (i != null)
                    {
                        selectedempmodel.Remove(i);
                    }
                }
            }
            
            
        }
        private string Contents { get; set; }

        void DGRole_ColumnDisplayIndexChanged(object sender, DataGridColumnEventArgs e)
        {
            //string result = string.Empty;
            //foreach(var column in DGRole.Columns.Where(c=>c.Visibility == System.Windows.Visibility.Visible))
            //{
            //    DataGridTextColumn tc = column as DataGridTextColumn;
            //    if (tc != null)
            //    {
            //        //result += column.Header.ToString() + "-" + column.DisplayIndex+";";
            //    }
            //}
            for (int i = 0; i < 41; i ++ )
            {
                if (!string.IsNullOrEmpty(e.Column.Header.ToString()) && e.Column.Header.ToString() == shuzu[i].Split('-')[0])
                {
                    shuzu[i] = shuzu[i].Split('-')[0] + "-" + shuzu[i].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                }
            }
                //switch (e.Column.Header.ToString())
                //{
                //    case "姓名":
                //        shuzu[0] = shuzu[0].Split('-')[0] + "-" + shuzu[0].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "证件号码":
                //        shuzu[1] = shuzu[1].Split('-')[0] + "-" + shuzu[1].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "性别":
                //        shuzu[2] = shuzu[2].Split('-')[0] + "-" + shuzu[2].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "出生日期":
                //        shuzu[3] = shuzu[3].Split('-')[0] + "-" + shuzu[3].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "退休时间":
                //        shuzu[4] = shuzu[4].Split('-')[0] + "-" + shuzu[4].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "距离退休年限":
                //        shuzu[5] = shuzu[5].Split('-')[0] + "-" + shuzu[5].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "出生地":
                //        shuzu[6] = shuzu[6].Split('-')[0] + "-" + shuzu[6].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "籍贯":
                //        shuzu[7] = shuzu[7].Split('-')[0] + "-" + shuzu[7].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "民族":
                //        shuzu[8] = shuzu[8].Split('-')[0] + "-" + shuzu[8].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "政治面貌":
                //        shuzu[9] = shuzu[9].Split('-')[0] + "-" + shuzu[9].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "健康状况":
                //        shuzu[10] = shuzu[10].Split('-')[0] + "-" + shuzu[10].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "参加工作日期":
                //        shuzu[11] = shuzu[11].Split('-')[0] + "-" + shuzu[11].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "现工作单位":
                //        shuzu[12] = shuzu[12].Split('-')[0] + "-" + shuzu[12].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "现工作部门":
                //        shuzu[13] = shuzu[13].Split('-')[0] + "-" + shuzu[13].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "公务员登记号":
                //        shuzu[14] = shuzu[14].Split('-')[0] + "-" + shuzu[14].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "人员编制类型":
                //        shuzu[15] = shuzu[15].Split('-')[0] + "-" + shuzu[15].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "进本单位时间":
                //        shuzu[16] = shuzu[16].Split('-')[0] + "-" + shuzu[16].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "获本区公务员身份方式":
                //        shuzu[17] = shuzu[17].Split('-')[0] + "-" + shuzu[17].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "户籍所在地":
                //        shuzu[18] = shuzu[18].Split('-')[0] + "-" + shuzu[18].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "婚姻状况":
                //        shuzu[19] = shuzu[19].Split('-')[0] + "-" + shuzu[19].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "家庭住址":
                //        shuzu[20] = shuzu[20].Split('-')[0] + "-" + shuzu[20].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "住宅电话":
                //        shuzu[21] = shuzu[21].Split('-')[0] + "-" + shuzu[21].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;

                //    case "个人身份":
                //        shuzu[22] = shuzu[22].Split('-')[0] + "-" + shuzu[22].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "入党时间":
                //        shuzu[23] = shuzu[23].Split('-')[0] + "-" + shuzu[23].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "专长":
                //        shuzu[24] = shuzu[24].Split('-')[0] + "-" + shuzu[24].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "专业技术职务":
                //        shuzu[25] = shuzu[25].Split('-')[0] + "-" + shuzu[25].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "人员类别":
                //        shuzu[26] = shuzu[26].Split('-')[0] + "-" + shuzu[26].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "公务员登记时间":
                //        shuzu[27] = shuzu[27].Split('-')[0] + "-" + shuzu[27].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "职务代码":
                //        shuzu[28] = shuzu[28].Split('-')[0] + "-" + shuzu[28].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "现任职务":
                //        shuzu[29] = shuzu[29].Split('-')[0] + "-" + shuzu[29].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "职务层次":
                //        shuzu[30] = shuzu[30].Split('-')[0] + "-" + shuzu[30].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "职务属性":
                //        shuzu[31] = shuzu[31].Split('-')[0] + "-" + shuzu[31].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "批准时间":
                //        shuzu[32] = shuzu[32].Split('-')[0] + "-" + shuzu[32].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "任职方式":
                //        shuzu[33] = shuzu[33].Split('-')[0] + "-" + shuzu[33].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "任现职务层次时间":
                //        shuzu[34] = shuzu[34].Split('-')[0] + "-" + shuzu[34].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "任现职务属性时间":
                //        shuzu[35] = shuzu[35].Split('-')[0] + "-" + shuzu[35].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;

                //    case "学历名称":
                //        shuzu[36] = shuzu[36].Split('-')[0] + "-" + shuzu[36].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "学习形式":
                //        shuzu[37] = shuzu[37].Split('-')[0] + "-" + shuzu[37].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "毕业日期":
                //        shuzu[38] = shuzu[38].Split('-')[0] + "-" + shuzu[38].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "学校":
                //        shuzu[39] = shuzu[39].Split('-')[0] + "-" + shuzu[39].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //    case "所学专业":
                //        shuzu[40] = shuzu[40].Split('-')[0] + "-" + shuzu[40].Split('-')[1] + "-" + e.Column.DisplayIndex.ToString();
                //        break;
                //}
            
        }
        private void SavePeiZhiData_Click(object sender, RoutedEventArgs e)
        {
            string con = "";
            foreach (string i in shuzu)
            {
                con = con + i + ",";
            }
            con = con.Substring(0, con.Length - 1);
            model1.UserID = Session.LoginUser.UserID;
            model1.Content = con;
            
            Client.UpdateLieAsync(model1);
        }
        void Client_UpdateLieCompleted(object sender, UpdateLieCompletedEventArgs e)
        {
            MessageBox.Show("保存成功！");
        }

        private string[] PaiXu(string[] list)
        {
            if (list.Count() > 0)
            {
                for (int i = 0; i < list.Count(); i++)
                {
                    for (int j = i; j < list.Count(); j++)
                    {
                        if (Convert.ToInt32(list[i].Split('-')[2]) > Convert.ToInt32(list[j].Split('-')[2]))
                        {
                            string k = list[j];
                            list[j] = list[i];
                            list[i] = k;
                        }
                    }
                }
            }
            return list;
        }
        private PeiZhiLieModel model1 = new PeiZhiLieModel();
        private string[] shuzu = null;
        void Client_GetLieByUserIDCompleted(object sender, GetLieByUserIDCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                model1 = e.Result;
                Contents = ((PeiZhiLieModel)e.Result).Content;
            }
            if (string.IsNullOrEmpty(Contents))
            {
                Contents =
                     @"姓名-true-1000,证件号码-true-1000,性别-true-1000,出生日期-true-1000,退休时间-true-1000,距离退休年限-true-1000,出生地-true-1000,籍贯-true-1000,民族-true-1000,政治面貌-true-1000,健康状况-true-1000,参加工作日期-true-1000,现工作单位-true-1000,现工作部门-true-1000,公务员登记号-true-1000,人员编制类型-true-1000,进本单位时间-true-1000,获本区公务员身份方式-true-1000,户籍所在地-true-1000,婚姻状况-true-1000,家庭住址-true-1000,住宅电话-true-1000,个人身份-true-1000,入党时间-true-1000,专长-true-1000,专业技术职务-true-1000,人员类别-true-1000,公务员登记时间-true-1000,职务代码-true-1000,现任职务-true-1000,职务层次-true-1000,职务属性-true-1000,批准时间-true-1000,任职方式-true-1000,任现职务层次时间-true-1000,任现职务属性时间-true-1000,学历名称-true-1000,学习形式-true-1000,毕业日期-true-1000,学校-true-1000,所学专业-true-1000,学位毕业时间-true-1000";
            }
            if (DGRole.Columns.Count == 2)
            {
                shuzu = Contents.Split(',');
                shuzu = PaiXu(shuzu);
                //if(Convert.ToInt32(shuzu[0].Split('-')[2]))
                foreach (string i in shuzu)
                {
                    if (i.Split('-')[0] == "姓名" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "姓名";
                        column.Binding = new Binding("Name");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "证件号码" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "证件号码";
                        column.Binding = new Binding("CardNo");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "性别" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "性别";
                        column.Binding = new Binding("Gender");
                        column.Width = new DataGridLength(80);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "出生日期" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "出生日期";
                        Binding binding = new Binding("Birthday");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "退休时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "退休时间";
                        Binding binding = new Binding("TuiXiuDateString");
                        //binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "距离退休年限" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "距离退休年限";
                        column.Binding = new Binding("JuTuiXiuDate");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "出生地" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "出生地";
                        column.Binding = new Binding("BirthPlace");
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "籍贯" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "籍贯";
                        column.Binding = new Binding("NativePlace");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "民族" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "民族";
                        column.Binding = new Binding("Native");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "政治面貌" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "政治面貌";
                        column.Binding = new Binding("Political");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "健康状况" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "健康状况";
                        column.Binding = new Binding("Health");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "参加工作日期" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "参加工作日期";
                        Binding binding = new Binding("WorkDate");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "现工作单位" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "现工作单位";
                        column.Binding = new Binding("OrgName");
                        column.Width = new DataGridLength(250);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "现工作部门" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "现工作部门";
                        column.Binding = new Binding("PositionName");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "公务员登记号" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "公务员登记号";
                        column.Binding = new Binding("RegisterNo");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "人员编制类型" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "人员编制类型";
                        column.Binding = new Binding("OrganizationType");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "进本单位时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "进本单位时间";
                        Binding binding = new Binding("NowWorkDate");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "获本区公务员身份方式" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "获本区公务员身份方式";
                        column.Binding = new Binding("HuoDeFangShi");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "户籍所在地" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "户籍所在地";
                        column.Binding = new Binding("HouseholdRegister");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "婚姻状况" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "婚姻状况";
                        column.Binding = new Binding("Marriage");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "家庭住址" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "家庭住址";
                        column.Binding = new Binding("HomeAddress");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "住宅电话" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "住宅电话";
                        column.Binding = new Binding("Phone");
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "个人身份" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "个人身份";
                        column.Binding = new Binding("EmpIdentity");
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "入党时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "入党时间";
                        Binding binding = new Binding("PartyTime");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "专长" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "专长";
                        column.Binding = new Binding("Special");
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "专业技术职务" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "专业技术职务";
                        column.Binding = new Binding("TechnicalPositions");
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "人员类别" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "人员类别";
                        column.Binding = new Binding("PersonnelType");
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "公务员登记时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "公务员登记时间";
                        Binding binding = new Binding("RegisterDate");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "职务代码" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "职务代码";
                        column.Binding = new Binding("DutyNo");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "现任职务" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "现任职务";
                        column.Binding = new Binding("DutyName");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "职务层次" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "职务层次";
                        column.Binding = new Binding("DutyLevel");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "职务属性" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "职务属性";
                        column.Binding = new Binding("DutyAttribute");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "任职方式" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "任职方式";
                        column.Binding = new Binding("ServiceMode");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "批准时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "批准时间";
                        Binding binding = new Binding("OKDate");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "任现职务层次时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "任现职务层次时间";
                        Binding binding = new Binding("JobDate");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "任现职务属性时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "任现职务属性时间";
                        Binding binding = new Binding("RXRZWSXSJ");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "学历名称" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "学历名称";
                        column.Binding = new Binding("EducationName");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "学习形式" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "学习形式";
                        column.Binding = new Binding("EducationType");
                        column.Width = new DataGridLength(100);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "毕业日期" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "毕业日期";
                        Binding binding = new Binding("GraduationDate");
                        binding.StringFormat = "yyyy-MM-dd";
                        column.Binding = binding;
                        column.Width = new DataGridLength(120);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "学校" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "学校";
                        column.Binding = new Binding("School");
                        column.Width = new DataGridLength(200);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "所学专业" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "所学专业";
                        column.Binding = new Binding("Professional");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                    if (i.Split('-')[0] == "学位毕业时间" && i.Split('-')[1] == "true")
                    {
                        DataGridTextColumn column = new DataGridTextColumn();
                        column.Header = "学位毕业时间";
                        column.Binding = new Binding("DegreeGraduation");
                        column.Width = new DataGridLength(150);
                        column.IsReadOnly = true;

                        DGRole.Columns.Add(column);
                    }
                }
                DGRole.Columns.OrderBy(p => p.DisplayIndex);
            }



        }

        void Client_GetEmp_BasicInfoCountsCompleted(object sender, EmpbasicService.GetEmp_BasicInfoCountsCompletedEventArgs e)
        {
            int count = e.Result;
            ///每次查询后清空选中人员
            if (selectedempmodel != null)
                selectedempmodel.Clear();
            ObservableCollection<int> source = new ObservableCollection<int>();
            for (int i = 0; i < count; i++)
            {
                source.Add(i + 1);
            }
            PagedCollectionView pcv = new PagedCollectionView(source);
            dataPager1.PageSize = 1;
            dataPager1.Source = pcv;
        }
        private void dataPager1_PageIndexChanged(object sender, EventArgs e)
        {
            int index = dataPager1.PageIndex;
            if (DGRole.ItemsSource != null)
            {
                foreach (EmpbasicService.Emp_BasicInfoModel i in (ObservableCollection<EmpbasicService.Emp_BasicInfoModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            string ss = "";
            foreach (string ii in orgids)
                ss += ii + ",";
            if (string.IsNullOrEmpty(ss))
            {
                ss = "0";
            }
            else
            {
                ss = ss.Substring(0, ss.Length - 1);
            }


            Client.GetEmp_BasicInfoAsync(ss, "0", ChaName.Text, type, index * 20, index * 20 + 20, shiti.ygzt, GetHightCondition());
            rootIndicator.BusyContent = "查询数据....";
            rootIndicator.IsBusy = true;
        }
        public ObservableCollection<EmpbasicService.OrgForHRModel> OrgList =
            new ObservableCollection<EmpbasicService.OrgForHRModel>();
        void Client_GetDengLuJueSeCompleted(object sender, EmpbasicService.GetDengLuJueSeCompletedEventArgs e)
        {
            if (e.Result != "人事干部")
            {
                if (TreeOfLife.ItemsSource != null) TreeOfLife.ItemsSource = null;
                TreeOfLife.Visibility = System.Windows.Visibility.Visible;
                ListBoxOfLife.Visibility = System.Windows.Visibility.Collapsed;
                DeleteData.Visibility = System.Windows.Visibility.Visible;
                NewData.Visibility = System.Windows.Visibility.Visible;
                //colLeft.Width = new GridLength(265);
                //colSplit.Width = new GridLength(10);
                LoadData("0");
                Client.GetOrgForHRModelAsync(0);

            }
            else
            {
                TreeOfLife.Visibility = System.Windows.Visibility.Collapsed;
                ListBoxOfLife.Visibility = System.Windows.Visibility.Visible;
                DeleteData.Visibility = System.Windows.Visibility.Collapsed;
                NewData.Visibility = System.Windows.Visibility.Collapsed;
                Client.GetDengLuOrgAsync(Session.LoginUser.LoginName);
                //colLeft.Width = new GridLength(0);
                //colSplit.Width = new GridLength(0);
            }
        }

        void Client_GetDengLuOrgCompleted(object sender, EmpbasicService.GetDengLuOrgCompletedEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.Result))
            {
                Oldorgids = e.Result.Split(',');
            }
            Client.GetOrgForHRModelbyIDsAsync("(" + e.Result + ")");
        }

        void Client_GetOrgForHRModelbyIDsCompleted(object sender, EmpbasicService.GetOrgForHRModelbyIDsCompletedEventArgs e)
        {
            ListBoxOfLife.ItemsSource = e.Result;
            ListBoxOfLife.SelectedIndex = 0;
            orgid = Convert.ToInt32(e.Result[0].ID);
            //if (!orgids.Contains(orgid.ToString())) orgids.Add(orgid.ToString());
            //string ss = "";
            //foreach (string ii in orgids)
            //    ss += ii + ",";
            //ss = ss.Substring(0, ss.Length - 1);
            orgids.Clear();
            orgids.Add(orgid.ToString());
            LoadData(orgids[0]);
        }
        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            orgid = Convert.ToInt32(((OrgForHRModel)(ListBoxOfLife.SelectedItem)).ID);
            tbTitle.Text = ((OrgForHRModel) (ListBoxOfLife.SelectedItem)).Name;
            Client.GetBianZhiModelShiYouCompleted -= new EventHandler<EmpbasicService.GetBianZhiModelShiYouCompletedEventArgs>(Client_GetBianZhiModelShiYouCompleted);
            Client.GetBianZhiModelShiYouCompleted += new EventHandler<EmpbasicService.GetBianZhiModelShiYouCompletedEventArgs>(Client_GetBianZhiModelShiYouCompleted);
            Client.GetBianZhiModelShiYouAsync(orgid);
            //if (!orgids.Contains(orgid.ToString())) orgids.Add(orgid.ToString());
            //string ss = "";
            //foreach (string ii in orgids)
            //    ss += ii + ",";
            //ss = ss.Substring(0, ss.Length - 1);
            orgids.Clear();
            orgids.Add(orgid.ToString());
            LoadData(orgids[0]);
        }

        void Client_GetOrgForHRModelCompleted(object sender, EmpbasicService.GetOrgForHRModelCompletedEventArgs e)
        {
            OrgList = e.Result;
            forumList.Clear();
            foreach (EmpbasicService.OrgForHRModel i in e.Result)
            {
                forumList.Add(i);
            }
            //forumList.Add(new EmpbasicService.OrgForHRModel() { ID = 1, Type = "全部单位", Name = "组织机构" });
            //forumList.Add(new EmpbasicService.OrgForHRModel() { ID = 1, Type = "组织机构", Name = "党群系统" });
            //forumList.Add(new EmpbasicService.OrgForHRModel() { ID = 1, Type = "组织机构", Name = "政法系统" });

            //forumList.Add(new EmpbasicService.OrgForHRModel() { ID = 1, Type = "组织机构", Name = "行政系统" });
            //forumList.Add(new EmpbasicService.OrgForHRModel() { ID = 1, Type = "组织机构", Name = "参公系统" });
            //forumList.Add(new EmpbasicService.OrgForHRModel() { ID = 1, Type = "组织机构", Name = "地区系统" });
            AddTreeNode("全部单位", null);
        }

        

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            foreach (EmpbasicService.Emp_BasicInfoModel p in DGRole.ItemsSource)
            {
                p.IsSelected = (bool)cb.IsChecked;
                //CheckBox cb1 = DGRole.Columns[0].GetCellContent(p) as CheckBox;
                //cb1.IsChecked = p.IsSelected;
                if (p.IsSelected)
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(p);
                    }
                }
                else
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() != null)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault());
                    }
                }
            }

        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewData_Click(object sender, RoutedEventArgs e)
        {
            if (orgids.Count != 1)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("只能针对一个单位进行人员的新增！"); 
                return;
            }
            EmpbasicWindow RMWindow = new EmpbasicWindow(0, true, Convert.ToInt32(orgids[0]), shiti.ygzt);
            RMWindow.Closed += new EventHandler(RMWindow_Closed);
            RMWindow.Show();
        }
        void RMWindow_Closed(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            string ss = "";
            foreach (string ii in orgids)
                ss += ii + ",";
            if (string.IsNullOrEmpty(ss)) ss = "0";
            else ss = ss.Substring(0, ss.Length - 1);
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (EmpbasicService.Emp_BasicInfoModel i in (ObservableCollection<EmpbasicService.Emp_BasicInfoModel>)DGRole.ItemsSource)
                {
                    i.IsSelected = false;
                }
            }
            LoadData(ss);
        }

        private void EditData_Click(object sender, RoutedEventArgs e)
        {
            //var seljw = this.DGRole.SelectedItem as EmpbasicService.Emp_BasicInfoModel;
            //var ss = DGRole.GetSelectedItems<EmpbasicService.Emp_BasicInfoModel>();
            //throw new NotImplementedException();

            if (DGRole.ItemsSource != null)
            {
                foreach (EmpbasicService.Emp_BasicInfoModel i in (ObservableCollection<EmpbasicService.Emp_BasicInfoModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (selectedempmodel.Count > 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能选择一个人员进行编辑！"); 
                    return;
                }
                EmpbasicWindow RMWindow = new EmpbasicWindow(selectedempmodel[0].ID, false, 0, shiti.ygzt);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的人员！"); 
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteData_Click(object sender, RoutedEventArgs e)
        {
            //var seljw = this.DGRole.SelectedItem as EmpbasicService.Emp_BasicInfoModel;
            //string strID = "";
            //foreach (object ovj in DGRole.ItemsSource)
            //{
            //    CheckBox cb1 = DGRole.Columns[0].GetCellContent(ovj).FindName("ck") as CheckBox;

            //    if (cb1.IsChecked.Value)
            //        strID = strID + cb1.Tag + ",";
            //}
            //多选
            // var ss = DGRole.GetSelectedItems<EmpbasicService.Emp_BasicInfoModel>();

            //throw new NotImplementedException();
            if (DGRole.ItemsSource != null)
            {
                foreach (EmpbasicService.Emp_BasicInfoModel i in (ObservableCollection<EmpbasicService.Emp_BasicInfoModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (MessageBox.Show("确定删除吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    string ids = "";

                    foreach (EmpbasicService.Emp_BasicInfoModel i in selectedempmodel)
                    {
                        ids += i.ID.ToString() + ",";
                    }

                    Client.DeleteEmp_BasicInfoCompleted -= new EventHandler<EmpbasicService.DeleteEmp_BasicInfoCompletedEventArgs>(Client_DeleteEmp_BasicInfoCompleted);
                    Client.DeleteEmp_BasicInfoCompleted += new EventHandler<EmpbasicService.DeleteEmp_BasicInfoCompletedEventArgs>(Client_DeleteEmp_BasicInfoCompleted);
                    Client.DeleteEmp_BasicInfoAsync("(" + ids.Substring(0, ids.Length - 1) + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要删除的人员信息！"); 
        }

        void Client_DeleteEmp_BasicInfoCompleted(object sender, EmpbasicService.DeleteEmp_BasicInfoCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("删除成功！"); 
            string ss = "";
            foreach (string ii in orgids)
                ss += ii + ",";
            if (string.IsNullOrEmpty(ss)) ss = "0";
            else ss = ss.Substring(0, ss.Length - 1);
            LoadData(ss);
        }


        /// <summary>
        /// 查看其他信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImageButton_Click(object sender, RoutedEventArgs e)
        {
            //var ss = DGRole.GetSelectedItems<EmpbasicService.Emp_BasicInfoModel>();
            //var seljw = this.DGRole.SelectedItem as EmpbasicService.Emp_BasicInfoModel;

            foreach (EmpbasicService.Emp_BasicInfoModel i in (ObservableCollection<EmpbasicService.Emp_BasicInfoModel>)DGRole.ItemsSource)
            {
                if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null) selectedempmodel.Add(i);
                if (i.IsSelected == false && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null)
                    selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
            }

            if (selectedempmodel.Count > 0)
            {
                if (selectedempmodel.Count > 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能选择一个人员进行查看！"); 
                    return;
                }
                OtherEmpInfo view = new OtherEmpInfo(selectedempmodel[0].ID);
                Nav.ShowNextPage(selectedempmodel[0].Name + "-详细信息", view, this);
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要查看的人员！"); 
        }

        
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            string ss = "";
            foreach (string ii in orgids)
                ss += ii + ",";
            if (ss.Length > 1)
                ss = ss.Substring(0, ss.Length - 1);
            else ss = "0";
            
            string condition  =   GetHightCondition();
            if (null != condition)
            {
                expander.IsExpanded = false;
                selectedempmodel.Clear();
                searchCondition = new string[6] { ss, "0", ChaName.Text, type, shiti.ygzt, condition };
                //Client.GetEmp_BasicInfoAsync(ss, "0", ChaName.Text, type, 0, 20, "在职", condition);
                Client.GetEmp_BasicInfoCountsAsync(ss, "0", ChaName.Text, type, shiti.ygzt, condition);
                rootIndicator.BusyContent = "查询数据....";
                rootIndicator.IsBusy = true;
            }
        }

        private string[] searchCondition = null;//保存最后一次查询条件
        ObservableCollection<EmpbasicService.OrgForHRModel> forumList = new ObservableCollection<EmpbasicService.OrgForHRModel>();

        public string IDS = "";
        private void AddTreeNode(string type, TreeViewItem treeViewItem)
        {
            List<EmpbasicService.OrgForHRModel> result = (from forumInfo in forumList
                                                          where forumInfo.Type == type
                                                          select forumInfo).ToList<EmpbasicService.OrgForHRModel>();

            if (result.Count > 0)
            {
                foreach (EmpbasicService.OrgForHRModel foruminfo in result)
                {
                    TreeViewItem objTreeNode = new TreeViewItem();

                    //StackPanel sp = new StackPanel();
                    CheckBox cb = new CheckBox();
                    cb.Content = foruminfo.Name;
                    cb.Tag = objTreeNode;
                    cb.DataContext = foruminfo;
                    //sp.Children.Add(cb);
                    cb.Click += new RoutedEventHandler(cb_Checked);
                    objTreeNode.Header = cb;
                    //objTreeNode.Header = foruminfo.Name;
                    //objTreeNode.DataContext = foruminfo;
                    //objTreeNode.Tag = foruminfo.ID;
                    if ((objTreeNode.Header as CheckBox).Content.ToString() == "组织机构") objTreeNode.IsExpanded = true;

                    //此样式将会添加的所有叶子结点上
                    //objTreeNode.ItemContainerStyle = this.Resources["RedItemStyle"] as Style;

                    //添加根节点
                    if (treeViewItem == null)
                    {
                        TreeOfLife.Items.Add(objTreeNode);
                    }
                    else
                    {
                        treeViewItem.Items.Add(objTreeNode);
                    }
                    AddTreeNode(foruminfo.Name, objTreeNode);
                }
            }
        }

        private int OrgID = 0;
        void cb_Checked(object sender, RoutedEventArgs e)
        {
            tbTitle.Text = "";
            CheckBox cb = sender as CheckBox;
            EmpbasicService.OrgForHRModel rm = cb.DataContext as EmpbasicService.OrgForHRModel;
            if (cb.IsChecked == true)
            {
                //if (orgids != null)
                //{
                //orgid = Convert.ToInt32(((EmpbasicService.OrgForHRModel)cb.DataContext).ID);
                //tbTitle.Text = cb.Content.ToString();
                if (!orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                    orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                string ss = "";
                foreach (string i in orgids)
                    ss += i + ",";
                if (string.IsNullOrEmpty(ss) || orgids.Contains("79")) ss = "0";
                else ss = ss.Substring(0, ss.Length - 1);
                LoadData(ss);
                if (orgids.Count == 1)
                {
                    if (orgids[0] != "0" && orgids[0] != "79" && orgids[0] != "80" && orgids[0] != "81" && orgids[0] != "82" && orgids[0] != "83" && orgids[0] != "84")
                    {
                        //OrgID = Convert.ToInt32(orgids[0]);
                        tbTitle.Visibility = System.Windows.Visibility.Visible;
                        tbTitle.Text = cb.Content.ToString();
                        
                    }
                }
                else
                {
                    //OrgID = 0;
                    
                    tbTitle.Visibility = System.Windows.Visibility.Collapsed;
                } 
                //}
                //else orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());

                //CheckParentItem(cb.Tag as TreeViewItem);
                CheckChildItem(cb.Tag as TreeViewItem);
            }
            else
            {
                //if (orgids != null)
                //{
                if (orgids != null)
                {
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                }
                string ss = "";
                foreach (string i in orgids)
                    ss += i + ",";
                if(ss.Length > 1) ss = ss.Substring(0, ss.Length - 1);
                //Client.GetEmp_BasicInfoCompleted -= new EventHandler<EmpbasicService.GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
                //Client.GetEmp_BasicInfoCompleted += new EventHandler<EmpbasicService.GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
                //Client.GetEmp_BasicInfoAsync(ss, "0", "", type, 0, 20);
                LoadData(ss);
                //}
                UnCheckChildItem(cb.Tag as TreeViewItem);
            }
        }
        void CheckParentItem(TreeViewItem item)
        {
            TreeViewItem tvi = item.GetParentTreeViewItem();
            if (tvi != null)
            {
                CheckBox cb = tvi.Header as CheckBox;
                cb.IsChecked = true;
                CheckParentItem(tvi);
            }
        }

        void CheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = true;
                    if (!orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    CheckChildItem(tvi);
                }
            }
        }
        void UnCheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = false;
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    UnCheckChildItem(tvi);
                }
            }
        }
        public int orgid { get; set; }
        public List<string> orgids = new List<string>();
        public string type { get; set; }
        private void TreeOfLife_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            orgid = 0;
            string type = "";
            TreeViewItem item = e.NewValue as TreeViewItem;
            if (item != null)
            {
                if (item.Header.ToString() == "组织机构")
                {
                    type = "组织机构";
                }
                else if (item.Header.ToString() == "党群系统")
                {
                    type = "党群系统";
                }
                else if (item.Header.ToString() == "政法系统")
                {
                    type = "政法系统";
                }
                else if (item.Header.ToString() == "行政系统")
                {
                    type = "行政系统";
                }
                else if (item.Header.ToString() == "参公系统")
                {
                    type = "参公系统";
                }
                else if (item.Header.ToString() == "地区系统")
                {
                    type = "地区系统";
                }
                else
                {
                    orgid = Convert.ToInt32(item.Tag);
                    tbTitle.Text = item.Header.ToString();
                }

                //orgid = Convert.ToInt32(((EmpbasicService.OrgForHRModel)(((CheckBox)item.Header).DataContext)).ID);

                //Client.GetEmp_BasicInfoCompleted -= new EventHandler<EmpbasicService.GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
                //Client.GetEmp_BasicInfoCompleted += new EventHandler<EmpbasicService.GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
                //Client.GetEmp_BasicInfoAsync(orgid, "0", "", type, 0, 20);


                if (orgid != 0 && orgid != 79 && orgid != 80 && orgid != 81 && orgid != 82 && orgid != 83 && orgid != 84)
                {
                    Client.GetBianZhiModelShiYouCompleted -= new EventHandler<EmpbasicService.GetBianZhiModelShiYouCompletedEventArgs>(Client_GetBianZhiModelShiYouCompleted);
                    Client.GetBianZhiModelShiYouCompleted += new EventHandler<EmpbasicService.GetBianZhiModelShiYouCompletedEventArgs>(Client_GetBianZhiModelShiYouCompleted);
                    Client.GetBianZhiModelShiYouAsync(orgid);


                }
            }
        }
        /// <summary>
        /// 人员列表上面的各单位的编制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Client_GetBianZhiModelShiYouCompleted(object sender, EmpbasicService.GetBianZhiModelShiYouCompletedEventArgs e)
        {
            if(e.Result != null && e.Result.Count > 0)
            {
                zongbianzhi.Text = !string.IsNullOrEmpty(e.Result[0].ZongBianZhi) ? e.Result[0].ZongBianZhi : "0";
                chuji.Text = !string.IsNullOrEmpty(e.Result[0].ChuJiRenShu) ? e.Result[0].ChuJiRenShu : "0";
                zhengkelingdao1.Text = !string.IsNullOrEmpty(e.Result[0].ZhengKeLingDaoShiYou) ? e.Result[0].ZhengKeLingDaoShiYou : "0";
                zhengkefeilingdao1.Text = !string.IsNullOrEmpty(e.Result[0].ZhengKeFeiLingDaoShiYou) ? e.Result[0].ZhengKeFeiLingDaoShiYou : "0";
                fukelingdao1.Text = !string.IsNullOrEmpty(e.Result[0].FuKeLingDaoShiYou) ? e.Result[0].FuKeLingDaoShiYou : "0";
                fukefeilingdao1.Text = !string.IsNullOrEmpty(e.Result[0].FuKeFeiLingDaoShiYou) ? e.Result[0].FuKeFeiLingDaoShiYou : "0";
                keyuan1.Text = !string.IsNullOrEmpty(e.Result[0].KeYuanShiYou) ? e.Result[0].KeYuanShiYou : "0";
                weidingzhi1.Text = !string.IsNullOrEmpty(e.Result[0].WeiDingZhi) ? e.Result[0].WeiDingZhi : "0";
                keji.Text = (Convert.ToInt32(zhengkelingdao1.Text) + Convert.ToInt32(zhengkefeilingdao1.Text)
                             + Convert.ToInt32(fukelingdao1.Text) + Convert.ToInt32(fukefeilingdao1.Text)
                             + Convert.ToInt32(keyuan1.Text) + Convert.ToInt32(weidingzhi1.Text)).ToString();
                Client.GetBianZhiModelCompleted += new EventHandler<EmpbasicService.GetBianZhiModelCompletedEventArgs>(Client_GetBianZhiModelCompleted);
                Client.GetBianZhiModelAsync(OrgID, 0);
            }
            
        }

        void Client_GetBianZhiModelCompleted(object sender, EmpbasicService.GetBianZhiModelCompletedEventArgs e)
        {
            if (e.Result != null && e.Result.Count > 0)
                model = e.Result[0];
            bianzhiqingkuang.DataContext = model;
            result();
        }

        public void result()
        {
            if (!string.IsNullOrEmpty(model.ZongBianZhi) && !string.IsNullOrEmpty(model.ChuJiRenShu))
            {
                if ((Convert.ToInt32(model.ZongBianZhi) - Convert.ToInt32(model.ChuJiRenShu) - Convert.ToInt32(keji.Text)) < 0)
                {
                    kongbian.Text =
                        (Convert.ToInt32(model.ZongBianZhi) - Convert.ToInt32(model.ChuJiRenShu) -
                         Convert.ToInt32(keji.Text)).ToString();
                    kongbian.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red);
                    kongbian.FontWeight = FontWeights.Bold;
                }
                else
                {
                    kongbian.Text =
                        (Convert.ToInt32(model.ZongBianZhi) - Convert.ToInt32(model.ChuJiRenShu) -
                         Convert.ToInt32(keji.Text)).ToString();
                    kongbian.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Black);
                    kongbian.FontWeight = FontWeights.Normal;
                }

            }
            if (!string.IsNullOrEmpty(model.ZhengKeLingDao))
            {
                if ((Convert.ToInt32(string.IsNullOrEmpty(zhengkelingdao1.Text) ? "0" : zhengkelingdao1.Text) - Convert.ToInt32(model.ZhengKeLingDao)) <= 0)
                {
                    zhengkelingdao2.Text = "无";
                    zhengkelingdao2.FontWeight = FontWeights.Normal;
                    zhengkelingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Black);
                }
                else
                {
                    zhengkelingdao2.Text =
                        (Convert.ToInt32(string.IsNullOrEmpty(zhengkelingdao1.Text) ? "0" : zhengkelingdao1.Text) - Convert.ToInt32(model.ZhengKeLingDao)).ToString();
                    zhengkelingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red);
                    zhengkelingdao2.FontWeight = FontWeights.Bold;
                }
            }
            if (!string.IsNullOrEmpty(model.ZhengKeFeiLingDao))
            {
                if ((Convert.ToInt32(string.IsNullOrEmpty(zhengkefeilingdao1.Text) ? "0" : zhengkefeilingdao1.Text) - Convert.ToInt32(model.ZhengKeFeiLingDao)) <= 0)
                {
                    zhengkefeilingdao2.Text = "无";
                    zhengkefeilingdao2.FontWeight = FontWeights.Normal;
                    zhengkefeilingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Black);
                }
                else
                {
                    zhengkefeilingdao2.Text =
                        (Convert.ToInt32(string.IsNullOrEmpty(zhengkefeilingdao1.Text) ? "0" : zhengkefeilingdao1.Text) - Convert.ToInt32(model.ZhengKeFeiLingDao)).ToString();
                    zhengkefeilingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red);
                    zhengkefeilingdao2.FontWeight = FontWeights.Bold;
                }
            }
            if (!string.IsNullOrEmpty(model.FuKeLingDao))
            {
                if ((Convert.ToInt32(string.IsNullOrEmpty(fukelingdao1.Text) ? "0" : fukelingdao1.Text) - Convert.ToInt32(model.FuKeLingDao)) <= 0)
                {
                    fukelingdao2.Text = "无";
                    fukelingdao2.FontWeight = FontWeights.Normal;
                    fukelingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Black);
                }
                else
                {
                    fukelingdao2.Text =
                        (Convert.ToInt32(string.IsNullOrEmpty(fukelingdao1.Text) ? "0" : fukelingdao1.Text) - Convert.ToInt32(model.FuKeLingDao)).ToString();
                    fukelingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red);
                    fukelingdao2.FontWeight = FontWeights.Bold;
                }
            }
            if (!string.IsNullOrEmpty(model.FuKeFeiLingDao))
            {
                if ((Convert.ToInt32(string.IsNullOrEmpty(fukefeilingdao1.Text) ? "0" : fukefeilingdao1.Text) - Convert.ToInt32(model.FuKeFeiLingDao)) <= 0)
                {
                    fukefeilingdao2.Text = "无";
                    fukefeilingdao2.FontWeight = FontWeights.Normal;
                    fukefeilingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Black);
                }
                else
                {
                    fukefeilingdao2.Text =
                        (Convert.ToInt32(string.IsNullOrEmpty(fukefeilingdao1.Text) ? "0" : fukefeilingdao1.Text) - Convert.ToInt32(model.FuKeFeiLingDao)).ToString();
                    fukefeilingdao2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red);
                    fukefeilingdao2.FontWeight = FontWeights.Bold;
                }
            }
            if (!string.IsNullOrEmpty(model.KeYuan))
            {
                if ((Convert.ToInt32(string.IsNullOrEmpty(keyuan1.Text) ? "0" : keyuan1.Text) - Convert.ToInt32(model.KeYuan)) <= 0)
                {
                    keyuan2.Text = "无";
                    keyuan2.FontWeight = FontWeights.Normal;
                    keyuan2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Black);
                }
                else
                {
                    keyuan2.Text =
                        (Convert.ToInt32(string.IsNullOrEmpty(keyuan1.Text) ? "0" : keyuan1.Text) - Convert.ToInt32(model.KeYuan)).ToString();
                    keyuan2.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red);
                    keyuan2.FontWeight = FontWeights.Bold;
                }
            }
        }

        //全选
        //private void CheckBox_Click(object sender, RoutedEventArgs e)
        //{
        //    if (DGRole.ItemsSource != null)
        //    {
        //        if (this.CBAll.IsChecked.Value)//全选
        //        {
        //            foreach (object ovj in DGRole.ItemsSource)
        //            {
        //                CheckBox cb1 = DGRole.Columns[0].GetCellContent(ovj).FindName("ck") as CheckBox; //cb为

        //                cb1.IsChecked = true;
        //            }
        //        }
        //        else//取消
        //        {
        //            foreach (object obj in DGRole.ItemsSource)
        //            {
        //                CheckBox cb2 = DGRole.Columns[0].GetCellContent(obj).FindName("ck") as CheckBox;

        //                cb2.IsChecked = false;
        //            }
        //        }
        //    }
        //}

        private GridLength _lastColLeftLength;
        private GridLength _lastColRightLength;
        private void GridSpliteTo_ToLeft(object sender, EventArgs e)
        {
            //已经到最左边，直接返回
            if (colLeft.Width.Value == 0.0)
            {
                return;
            }

            //
            if (colRight.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colLeft.Width = new GridLength(0);
                colRight.Width = new GridLength(150, GridUnitType.Star);
            }
        }

        private void GridSpliteTo_ToRight(object sender, EventArgs e)
        {
            if (colRight.Width.Value == 0)
            {
                return;
            }

            if (colLeft.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colRight.Width = new GridLength(0);
                colLeft.Width = new GridLength(300, GridUnitType.Star);
            }
        }

        /// <summary>
        /// 增加查询条件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Controls.Border b = new System.Windows.Controls.Border() { Margin = new Thickness(5, 2, 0, 2), 
                BorderThickness = new Thickness(1,1,1,1), BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.Green) };
            if (wp.Children.Count % 2 == 0)
            {
                b.Background = new SolidColorBrush(System.Windows.Media.Colors.LightGray);
            }
            StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal, VerticalAlignment= System.Windows.VerticalAlignment.Center };
            ComboBox cb = new ComboBox() { MinWidth = 80, DisplayMemberPath = "ColumnName", Tag="Condition",Margin = new Thickness(5, 5, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center };
            cb.ItemsSource = _AllColumnCollection;
            cb.SelectionChanged += (sender1, e1) =>
            {
                while (sp.Children.Count > 2)
                {
                    sp.Children.RemoveAt(1);
                }
                Query_ColumnCollection item = cb.SelectedItem as Query_ColumnCollection;
                ComboBox competor = new ComboBox() { MinWidth=80 ,Margin = new Thickness(5, 0, 0, 0), DisplayMemberPath = "Name", VerticalAlignment = System.Windows.VerticalAlignment.Center };
                int index = 1;
                switch (item.Type)
                {
                    case "字符型": 
                        competor.ItemsSource = QueryValueCompetor.StringCompetors;
                        sp.Children.Insert(index++,competor);
                        //sp.Children.Insert(index++,new TextBox() { Margin = new Thickness(5, 5, 0, 0) });
                        break;
                    case "数字型":
                        //sp.Children.Insert(index++, new TextBox() { Margin = new Thickness(5, 5, 0, 0) });
                        competor.ItemsSource = QueryValueCompetor.DateIntCompetors;
                        sp.Children.Insert(index++, competor);
                        break;
                    case "日期型":
                        competor.ItemsSource = QueryValueCompetor.DateIntCompetors;
                        sp.Children.Insert(index++, competor);
                        break;
                }
                competor.SelectionChanged += (sender2, e2) =>
                {
                    while (sp.Children.Count > 3)
                    {
                        sp.Children.RemoveAt(2);
                    }
                    var select = competor.SelectedItem as CompetorClass;
                    int selectIndex = sp.Children.IndexOf(competor);
                    switch (select.Sign)
                    {
                        case ">":
                        case "<":
                        case ">=":
                        case "<=":
                        case "=":
                        case "!=":
                            switch (item.Type)
                            {
                                case "字符型":
                                    sp.Children.Insert(2, new ComboBox() { MinWidth = 80, Margin = new Thickness(5, 0, 0, 0), DisplayMemberPath = "ColumnValue", VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    CustomerQueryClient.GetValuesAsync(item.Type, item.RangeSQL, EHR.Common.Session.LoginUser.LoginName, sp.Children[2]);
                                    break;
                                case "数字型":
                                    sp.Children.Insert(2, new TextBox() { MinWidth = 80, Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    break;
                                case "日期型":
                                    sp.Children.Insert(2, new DatePicker() { Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    break;
                            }
                            break;
                        case "in":
                        case "not in":
                        case "between":
                            switch (item.Type)
                            {
                                case "字符型":
                                    sp.Children.Insert(2, new TextBox() { MinWidth = 80, Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    break;
                                case "数字型":
                                    sp.Children.Insert(2, new TextBox() { MinWidth = 80, Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    sp.Children.Insert(3, new TextBlock() { Text = "到", Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    sp.Children.Insert(4, new TextBox() { MinWidth = 80, Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    break;
                                case "日期型":
                                    sp.Children.Insert(2, new DatePicker() { Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    sp.Children.Insert(3, new TextBlock() { Text = "到", Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    sp.Children.Insert(4, new DatePicker() { Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center });
                                    break;
                            }
                            break;
                    }
                };
            };
            Image delete = new Image() { Source = new BitmapImage(new Uri("/CommunitySystem;component/Images/ViewDesign/delete.png", UriKind.RelativeOrAbsolute)), Margin = new Thickness(5, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center };
            delete.MouseLeftButtonDown += (sender2, e2) =>
            {
                wp.Children.Remove(b);
            };
            sp.Children.Add(cb);
            sp.Children.Add(delete);
            b.Child = sp;
            int _index = wp.Children.IndexOf(img);
            wp.Children.Insert(_index, b);
        }

        /// <summary>
        /// 获得高级查询条件
        /// </summary>
        private string GetHightCondition()
        {
            StringBuilder condition = new StringBuilder();
            foreach (UIElement u in wp.Children)
            {
                StringBuilder subcondition = new StringBuilder();
                System.Windows.Controls.Border b = u as System.Windows.Controls.Border;
                if (b != null)
                {

                    StackPanel sp = b.Child as StackPanel;
                    if (sp != null)
                    {
                        #region columncode
                        ComboBox column = sp.Children[0] as ComboBox;
                        if (column.SelectedItem == null)
                            continue;
                        var item = column.SelectedItem as CommunitySystem.CustomerQuery.Query_ColumnCollection;
                        string pre = "";
                        switch (item.ColumnTable)
                        {
                            case "OrgForHR":
                                pre = "org";
                                break;
                            case "Emp_Duty":
                                pre = "duty";
                                break;
                            case "Emp_Education":
                                pre = "edu";
                                break;
                            case "Emp_Degree":
                                pre = "degree";
                                break;
                            default:
                                pre = "emp";
                                break;

                        }
                        subcondition.Append(string.Format(item.ColumnCode, pre));
                        #endregion

                        #region 匹配符
                        ComboBox cbCompeter = sp.Children[1] as ComboBox;
                        var compter = cbCompeter.SelectedItem as CompetorClass;
                        if (compter == null)
                            continue;
                        subcondition.Append("    ");
                        subcondition.Append(compter.Sign);
                        subcondition.Append("    ");
                        #endregion

                        #region 值
                        switch (item.Type)
                        {
                            case "字符型":
                               
                                switch (compter.Sign)
                                {
                                    case "in":
                                    case "not in":
                                        TextBox tb = sp.Children[2] as TextBox;
                                        tb.Text.Trim();
                                        if (tb.Text.StartsWith("(") && tb.Text.EndsWith(")"))
                                            subcondition.Append(tb.Text);
                                        else
                                        {
                                            SilverlightMessageBoxLibrary.Message.InfoMessage(item.ColumnName + "  查询条件值设置不正确!");
                                            return null;
                                        }
                                        break;
                                    default:
                                        ComboBox cb = sp.Children[2] as ComboBox;
                                        subcondition.Append("'");
                                        if(cb.SelectedValue == null)
                                        {
                                            SilverlightMessageBoxLibrary.Message.InfoMessage(item.ColumnName + "  查询条件值设置不正确!");
                                            return null;
                                        }
                                        var value = cb.SelectedItem as Query_ColumnValue;
                                        subcondition.Append(value.ColumnValue);
                                        subcondition.Append("'");
                                        break;

                                }
                                break;
                            case "数字型":
                                TextBox tb1 = sp.Children[2] as TextBox;
                                int start = 0;
                                if (tb1.Text != null && System.Text.RegularExpressions.Regex.IsMatch(tb1.Text, @"^-?\d+$"))
                                    start = int.Parse(tb1.Text);
                                else
                                {
                                    SilverlightMessageBoxLibrary.Message.ErrorMessage(item.ColumnName + "查询条件值设置不正确");
                                    continue;
                                }
                                switch (compter.Sign)
                                {
                                    case "between":
                                        int end = 0;
                                        TextBox tb2 = sp.Children[4] as TextBox;
                                        if (tb2.Text != null && System.Text.RegularExpressions.Regex.IsMatch(tb2.Text, @"^-?\d+$"))
                                            end = int.Parse(tb2.Text);
                                        else
                                        {
                                            SilverlightMessageBoxLibrary.Message.ErrorMessage(item.ColumnName + "查询条件值设置不正确");
                                            return null;
                                        }
                                        subcondition.Append(start);
                                        subcondition.Append("  and   ");
                                        subcondition.Append(end);
                                        break;
                                    default:
                                        subcondition.Append(start);
                                        break;
                                }
                                break;
                            case "日期型":
                                try
                                {
                                    DatePicker dp1 = sp.Children[2] as DatePicker;
                                    DateTime startDT = (DateTime)dp1.SelectedDate;

                                    switch (compter.Sign)
                                    {
                                        case "between":
                                            DateTime endDT = (DateTime)(sp.Children[4] as DatePicker).SelectedDate;
                                            subcondition.Append("'");
                                            subcondition.Append(startDT);
                                            subcondition.Append("'");
                                            subcondition.Append("  and   ");
                                            subcondition.Append("'");
                                            subcondition.Append(endDT);
                                            subcondition.Append("'");
                                            break;
                                        default:
                                            subcondition.Append("'");
                                            subcondition.Append(startDT);
                                            subcondition.Append("'");
                                            break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SilverlightMessageBoxLibrary.Message.ErrorMessage(item.ColumnName + "查询条件值设置不正确");
                                    return null;
                                }
                                break;
                        }


                        #endregion
                    }
                    if (subcondition.Length > 0)
                    {
                        if (condition.Length > 0)
                        {
                            condition.Append(" and ");
                            condition.Append(subcondition);
                        }
                        else
                            condition.Append(subcondition);
                    }
                }
            }
            return condition.ToString();
        }

        void CustomerQueryClient_GetValuesCompleted(object sender, GetValuesCompletedEventArgs e)
        {
            ComboBox cb = e.UserState as ComboBox;
            cb.ItemsSource = e.Result;
        }


        /// <summary>
        /// 清空所有
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            while (wp.Children.Count > 2)
            {
                wp.Children.RemoveAt(0);
            }
        }

        private void Export_Click(object sender, RoutedEventArgs e)
        {
            if (selectedempmodel.Count <= 0)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("请至少选择一条导出数据!");
                return;
            }
            var file = new SaveFileDialog() { Filter = "Excel 2003| *.xls" };
            if (file.ShowDialog() == true)
            {
                org.in2bits.MyXls.XlsDocument xls = new org.in2bits.MyXls.XlsDocument();
                var sheet = xls.Workbook.Worksheets.Add("Sheet 1");
                org.in2bits.MyXls.XF xf = xls.NewXF();
                xf.HorizontalAlignment = HorizontalAlignments.Centered;
                xf.VerticalAlignment = VerticalAlignments.Centered;
                InsertData(selectedempmodel, sheet, xf);
                using (Stream stream = file.OpenFile())
                {
                    xls.Save(stream);
                }
                SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功!");

            }
        }

        private void InsertData(ObservableCollection<EmpbasicService.Emp_BasicInfoModel> source, Worksheet sheet, XF xf)
        {
            int rowindex = 1;
            sheet.Rows.AddRow((ushort)rowindex);
            List<string> columns = new List<string>();
            string header = string.Empty;
            int columnindex = 1;
            sheet.Rows.AddRow((ushort)rowindex);
            foreach (var column in DGRole.Columns)
            {
                if (column.Equals(dtcXuhao) || column.Equals(dtcSelect))
                    continue;
                DataGridTextColumn dtc = column as DataGridTextColumn;
                
                if (dtc != null && dtc.Visibility == System.Windows.Visibility.Visible)
                {
                    header = dtc.Header.ToString();
                    columns.Add(dtc.Binding.Path.Path);
                    sheet.Cells.Add(rowindex, columnindex++, header, xf);
                }
            }
           
            foreach (var item in source)
            {
                 rowindex++;
                 columnindex = 1;
                sheet.Rows.AddRow((ushort)rowindex);
                foreach (string p in columns)
                {
                    PropertyInfo pi = item.GetType().GetProperty(p);
                    object value = pi.GetValue(item, null);
                    if (value != null && value is DateTime)
                    {
                        DateTime dt = (DateTime)value;
                        sheet.Cells.Add(rowindex, columnindex++, dt.ToString("yyyy-MM-dd"), xf);
                    }
                    else
                    {

                        sheet.Cells.Add(rowindex, columnindex++, value==null? "":value.ToString(), xf);
                    }
                }
            }

        }
        private int pagesize = 20;
        private SaveFileDialog _file = null;
        private void ExportAll_Click(object sender, RoutedEventArgs e)
        {
            _file = null;
            var file = new SaveFileDialog() { Filter = "Excel 2003| *.xls" };
            if (file.ShowDialog() == true)
            {
                _file = file;
                rootIndicator.BusyContent = "下载数据中...";
                rootIndicator.IsBusy = true;
                Client.GetEmp_BasicInfoCompleted -= new EventHandler<GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
                //Client.GetEmp_BasicInfoCompleted -= new EventHandler<GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
                Client.GetEmp_BasicInfoCompleted -= new EventHandler<GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted2);
                Client.GetEmp_BasicInfoCompleted += new EventHandler<GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted2);
                if (searchCondition != null)
                {
                    allsource = new List<Emp_BasicInfoModel>();
                    int i = 0;
                    Client.GetEmp_BasicInfoAsync(searchCondition[0], searchCondition[1], searchCondition[2],
                   searchCondition[3], i * pagesize, (i + 1) * pagesize, searchCondition[4],
                   searchCondition[5], i);
                }
            }
        }
        private List<CommunitySystem.EmpbasicService.Emp_BasicInfoModel> allsource = null;
        void Client_GetEmp_BasicInfoCompleted2(object sender, EmpbasicService.GetEmp_BasicInfoCompletedEventArgs e)
        {
            int i = Convert.ToInt32(e.UserState);
            allsource.AddRange(e.Result);
            if (i >= dataPager1.PageCount)//最后一页
            {

                org.in2bits.MyXls.XlsDocument xls = new org.in2bits.MyXls.XlsDocument();
                var sheet = xls.Workbook.Worksheets.Add("Sheet 1");
                org.in2bits.MyXls.XF xf = xls.NewXF();
                xf.HorizontalAlignment = HorizontalAlignments.Centered;
                xf.VerticalAlignment = VerticalAlignments.Centered;
                InsertData(new ObservableCollection<Emp_BasicInfoModel>(allsource), sheet, xf);
                using (Stream stream = _file.OpenFile())
                {
                    xls.Save(stream);
                }
                rootIndicator.IsBusy = false;
                SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功!");
                Client.GetEmp_BasicInfoCompleted -= new EventHandler<GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted2);
                Client.GetEmp_BasicInfoCompleted += new EventHandler<GetEmp_BasicInfoCompletedEventArgs>(Client_GetEmp_BasicInfoCompleted);
            }
            else
            {
                i++;
                Client.GetEmp_BasicInfoAsync(searchCondition[0], searchCondition[1], searchCondition[2],
                   searchCondition[3], i * pagesize, (i + 1) * pagesize, searchCondition[4],
                   searchCondition[5], i);
            }
            
            rootIndicator.IsBusy = false;
        }
       
    }

    public class OrgDemo
    {
        public int ID { get; set; }
        public int ParentID { get; set; }
        public string ForumName { get; set; }
    }

}
